package com.wcl.demo.ui.adapter;


import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wcl.demo.R;
import com.wcl.demo.model.entity.AroundInfor;

import java.util.List;


/**
 * Created by dllo on 15/11/30.
 */

public class NoteAdapter extends BaseAdapter {
    private List<AroundInfor> datas;

    public void addData(List<AroundInfor> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas != null && datas.size() > 0 ? datas.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (datas != null && datas.size() > 0) {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_note_item, null);
                holder.note_item_daysTv = (TextView) convertView.findViewById(R.id.note_item_daysTv);
                holder.note_monthTv = (TextView) convertView.findViewById(R.id.note_monthTv);
                holder.note_articleTv = (TextView) convertView.findViewById(R.id.note_articleTv);
                holder.note_item_picture = (ImageView) convertView.findViewById(R.id.note_item_picture);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.note_articleTv.setText(datas.get(position).getNote());
            holder.note_item_daysTv.setText(datas.get(position).getDate().toString());
            switch (datas.get(position).getMonth()) {
                case 1:
                    holder.note_monthTv.setText("一月");
                    break;
                case 2:
                    holder.note_monthTv.setText("二月");
                    break;
                case 3:
                    holder.note_monthTv.setText("三月");
                    break;
                case 4:
                    holder.note_monthTv.setText("四月");
                    break;
                case 5:
                    holder.note_monthTv.setText("五月");
                    break;
                case 6:
                    holder.note_monthTv.setText("六月");
                    break;
                case 7:
                    holder.note_monthTv.setText("七月");
                    break;
                case 8:
                    holder.note_monthTv.setText("八月");
                    break;
                case 9:
                    holder.note_monthTv.setText("九月");
                    break;
                case 10:
                    holder.note_monthTv.setText("十月");
                    break;
                case 11:
                    holder.note_monthTv.setText("十一月");
                    break;
                case 12:
                    holder.note_monthTv.setText("十二月");
                    break;

            }
            holder.note_item_picture.setImageBitmap(BitmapFactory.decodeFile(datas.get(position).getPictureKey()));

        }
        return convertView;

    }

    class ViewHolder {
        private TextView note_item_daysTv, note_monthTv, note_articleTv;
        private ImageView note_item_picture;
    }
}
